#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_ecp.info <<'%EOF%'
   rsp_ecp
   -------
   Molecule:         H2O
   Wave Function:    SCF / ECP 
   Test Purpose:     Calculation of energy and second hyperpolarizability
                     using ECP; test that Huckel works with ECP
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_ecp.mol <<'%EOF%'
ATOMBASIS
ECP test on H2O
----------------
Atomtypes=2 Generators=2 X Y
Charge=8.0 Atoms=1 Basis=ecp-sdd-DZ ECP=ecp-sdd-DZ
O       0.000000000000           0.0000000000           -0.1161156955
Charge=1.0 Atoms=1 Basis=6-31G*
H       0.000000000000           1.3457079896            0.9214202268
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_ecp.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**WAVE FUNCTIONS
.HF
*SCF INPUT
.DOUBLY OCCUPIED
 2 1 1 0
*ORBITAL
.MOSTART
 HUCKEL
**RESPONSE
*CUBIC       
.DIPLEN
.THCLR
1.0D-6
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_ecp.check
cat >>rsp_ecp.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# ECP
CRIT1=`$GREP "Pseudo potential parameters for ECP type * 1\." $log | wc -l`
CRIT2=`$GREP "Atomic charge * \: * 8\.0" $log | wc -l`
CRIT3=`$GREP "Effectiv charge\: * 6\.0" $log | wc -l`
CRIT4=`$GREP "Core electrons \: * 2" $log | wc -l`
CRIT5=`$GREP "Max angular mom\: * 2" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[1]=5
ERROR[1]="ECP ON OXYGEN NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "O * 1 * 6\.0000 * 16 * 8 * \[4s4p\|2s2p\]" $log | wc -l`
CRIT2=`$GREP "H * 2 * 1\.0000 * 4 * 2 * \[4s\|2s\]" $log | wc -l`
CRIT3=`$GREP "total\: * 3 * 8\.0000 * 24 * 12" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[2]=3
ERROR[2]="BASIS SET NOT SET UP CORRECTLY"

# Geometry
CRIT1=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT2=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "3 * z * (\-0| \-)\.1161156955" $log | wc -l`
CRIT4=`$GREP "4 * x * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "5 * y * 1\.3457079896" $log | wc -l`
CRIT6=`$GREP "6 * z * (0| )\.9214202268" $log | wc -l`
CRIT7=`$GREP "7 * x * (0| )\.0000000000" $log | wc -l`
CRIT8=`$GREP "8 * y * \-1\.3457079896" $log | wc -l`
CRIT9=`$GREP "9 * z * (0| )\.9214202268" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[3]=9
ERROR[3]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 3 * 2 * 3 * 1" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 6 * 2 * 4 * 0" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="SYMMETRY NOT CORRECT"

# Energy
CRIT1=`$GREP "Final * HF energy\: * \-16\.880654969" $log | wc -l`
TEST[5]=`expr	$CRIT1`
CTRL[5]=1
ERROR[5]="SCF ENERGY NOT CORRECT"

# Response setup
CRIT1=`$GREP "Second hyperpolarizability calculation \: * CRCAL\= T" $log | wc -l`
CRIT2=`$GREP "1 B\-frequencies * (0| )\.000000(D|E)\+00" $log | wc -l`
CRIT3=`$GREP "1 C\-frequencies * (0| )\.000000(D|E)\+00" $log | wc -l`
CRIT4=`$GREP "1 D\-frequencies * (0| )\.000000(D|E)\+00" $log | wc -l`
CRIT5=`$GREP "1 A OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
CRIT6=`$GREP "1 B OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
CRIT7=`$GREP "1 C OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
CRIT8=`$GREP "1 D OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[6]=16
ERROR[6]="RESPONSE CALCULATION NOT SET UP CORRECTLY"

# Second hyperpolarizability
CRIT1=`$GREP "\@ gamma\(X\;X\,X\,X\) * 7\.739" $log | wc -l`
CRIT2=`$GREP "\@ gamma\(X\;X\,Y\,Y\) * 15\.199" $log | wc -l`
CRIT3=`$GREP "\@ gamma\(X\;Y\,Y\,X\) * 15\.199" $log | wc -l`
CRIT4=`$GREP "\@ gamma\(X\;Y\,X\,Y\) * 15\.199" $log | wc -l`
CRIT5=`$GREP "\@ gamma\(X\;X\,Z\,Z\) * 12\.22[01]" $log | wc -l`
CRIT6=`$GREP "\@ gamma\(X\;Z\,Z\,X\) * 12\.22[01]" $log | wc -l`
CRIT7=`$GREP "\@ gamma\(X\;Z\,X\,Z\) * 12\.22[01]" $log | wc -l`
CRIT8=`$GREP "\@ gamma\(Y\;Y\,X\,X\) * 15\.199" $log | wc -l`
CRIT9=`$GREP "\@ gamma\(Y\;X\,X\,Y\) * 15\.199" $log | wc -l`
CRIT10=`$GREP "\@ gamma\(Y\;X\,Y\,X\) * 15\.199" $log | wc -l`
CRIT11=`$GREP "\@ gamma\(Y\;Y\,Y\,Y\) * 173\.23" $log | wc -l`
CRIT12=`$GREP "\@ gamma\(Y\;Y\,Z\,Z\) * 124\.65" $log | wc -l`
CRIT13=`$GREP "\@ gamma\(Y\;Z\,Z\,Y\) * 124\.65" $log | wc -l`
CRIT14=`$GREP "\@ gamma\(Y\;Z\,Y\,Z\) * 124\.65" $log | wc -l`
CRIT15=`$GREP "\@ gamma\(Z\;Z\,X\,X\) * 12\.22[01]" $log | wc -l`
CRIT16=`$GREP "\@ gamma\(Z\;X\,X\,Z\) * 12\.22[01]" $log | wc -l`
CRIT17=`$GREP "\@ gamma\(Z\;X\,Z\,X\) * 12\.22[01]" $log | wc -l`
CRIT18=`$GREP "\@ gamma\(Z\;Z\,Y\,Y\) * 124\.65" $log | wc -l`
CRIT19=`$GREP "\@ gamma\(Z\;Y\,Y\,Z\) * 124\.65" $log | wc -l`
CRIT20=`$GREP "\@ gamma\(Z\;Y\,Z\,Y\) * 124\.65" $log | wc -l`
CRIT21=`$GREP "\@ gamma\(Z\;Z\,Z\,Z\) *  97\.91" $log | wc -l`
CRIT22=`$GREP "\@ Averaged gamma parallel to the applied field is * 116\.6[01]" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ \
		$CRIT19 \+ $CRIT20 \+ $CRIT21 \+ $CRIT22`
CTRL[7]=22
ERROR[7]="SECOND HYPERPOLARIZABILITY NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
